package com.tuanzi.loan.business.service.receipt.statistics.impl;

import com.google.common.collect.Lists;
import com.tuanzi.loan.business.entity.receipt.statistics.ReceiptRechargeOrder;
import com.tuanzi.loan.business.repository.receipt.statistics.ReceiptRechargeOrderRepository;
import com.tuanzi.loan.business.service.receipt.statistics.ReceiptRechargeOrderService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.core.service.CommonServiceImpl;
import com.tuanzi.server.loan_base.constant.receipt.LoanReceiptRechargeOrderStatus;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Debug
@Service
@Transactional
public class ReceiptRechargeOrderServiceImpl extends CommonServiceImpl<ReceiptRechargeOrder, Long> implements ReceiptRechargeOrderService{
	
	@Autowired
	private ReceiptRechargeOrderRepository receiptRechargeOrderRepository;

	@Override
	public ReceiptRechargeOrder findLoanReceiptRechargeOrderByOrderId(String orderId) {
		return receiptRechargeOrderRepository.findLoanReceiptRechargeOrderByOrderId(orderId);
	}

	@Override
	protected JpaRepository<ReceiptRechargeOrder, Long> getRepository() {
		return receiptRechargeOrderRepository;
	}

	@Override
	public List<ReceiptRechargeOrder> findByLoanReceiptSystemUserIdAndCreateTimeBetween(String userId, Date startTime, Date endTime) {
		return receiptRechargeOrderRepository.findByLoanReceiptSystemUserIdAndCreateTimeBetween(userId, startTime, endTime);
	}

	@Override
	public List<ReceiptRechargeOrder> findReceiptRechargeOrdersByLoanReceiptSystemUserIdAndPayTimeBetweenWhereIsDone(String receiptUserId, Date startTime, Date endTime) {
		if(StringUtils.isBlank(receiptUserId)){
			return  Lists.newArrayList();
		}
		return receiptRechargeOrderRepository.findReceiptRechargeOrdersByLoanReceiptSystemUserIdAndOrderStatusAndPayTimeBetween(receiptUserId, LoanReceiptRechargeOrderStatus.DONE, startTime, endTime);
	}
}
